package binary_tree_implementation

import "algo-sdk-go/algo/data_struct/tree"

// 根据二叉树, 输出先序遍历
func (bt *BinaryTree) BT2ArrayByPreOrder(root *tree.TreeNode) []int {
	if root == nil {
		return nil
	}
	result := append(bt.BT2ArrayByPreOrder(root.Left), bt.BT2ArrayByPreOrder(root.Right)...)
	return append([]int{root.Value}, result...)
}

// 根据二叉树, 输出中序遍历
func (bt *BinaryTree) BT2ArrayByInOrder(root *tree.TreeNode) []int {
	return nil
}

// 根据二叉树, 输出后序遍历
func (bt *BinaryTree) BT2ArrayByPostOrder(root *tree.TreeNode) []int {
	return nil
}

// 根据二叉树, 输出层级遍历
func (bt *BinaryTree) BT2ArrayByLevelOrder(root *tree.TreeNode) []int {
	return nil
}

func (bt *BinaryTree) BT2ArrayByPreOrder1(root *tree.TreeNode) []int {
	var (
		result []int
		roll   func(root *tree.TreeNode)
	)
	if root == nil {
		return nil
	}

	roll = func(root *tree.TreeNode) {
		if root == nil {
			return
		}
		result = append(result, root.Value)
		roll(root.Left)
		roll(root.Right)
	}
	roll(root)
	return result
}
